//
//  HMGuideController.m
//  UI进阶-21-网易彩票
//
//  Created by 柯平常 on 16/4/7.
//  Copyright © 2016年 柯平常. All rights reserved.
//

#import "HMGuideController.h"
#import "HMGuideCell.h"

@interface HMGuideController ()

//定义数组 用来存储图片
@property (nonatomic, strong) NSArray *imageArr;

//把三个图片控件设置成属性
@property (nonatomic, weak) UIImageView *guide;



@end

@implementation HMGuideController

//重写init方法 布局
-(instancetype)init{
    
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc]init];
    //单个cell的大小
    layout.itemSize = [UIScreen mainScreen].bounds.size;
    
    //设置滚动方向
    layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
    //设置间距
    layout.minimumLineSpacing = 0;
    
    
    return [super initWithCollectionViewLayout:layout];
}



static NSString * const reuseIdentifier = @"Cell";

- (void)viewDidLoad {
    [super viewDidLoad];
    
    //设置颜色
    //    self.collectionView.backgroundColor = [UIColor grayColor];
    
    //设置分页
    self.collectionView.pagingEnabled = YES;
    
    //隐藏水平 和竖直的滚动条,取消弹簧
    self.collectionView.bounces = NO;
    self.collectionView.showsVerticalScrollIndicator = NO;
    self.collectionView.showsHorizontalScrollIndicator = NO;
    
    //注册cell
    [self.collectionView registerClass:[HMGuideCell class] forCellWithReuseIdentifier:reuseIdentifier];
    
}

#pragma mark <UICollectionViewDataSource>

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
    
    return 1;
}


- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    
    return self.imageArr.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    HMGuideCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:reuseIdentifier forIndexPath:indexPath];
    
    //    cell.backgroundColor = [UIColor colorWithPatternImage:self.imageArr[indexPath.item]];
    cell.backgroundView = [[UIImageView alloc]initWithImage:self.imageArr[indexPath.item]];

    if (indexPath.item == self.imageArr.count - 1 ) {
        
        cell.go2Btn.hidden = NO;
        
    }else{
        
        cell.go2Btn.hidden = YES;
    }
    
    
    return cell;
}

//MARK:  -数组懒加载
-(NSArray *)imageArr{
    if (_imageArr ==nil) {
        NSMutableArray *arrM = [NSMutableArray array];
        for (NSInteger i = 0; i < 2; ++i) {
            [arrM addObject:[UIImage imageNamed:[NSString stringWithFormat:@"guide_page%@",@(i+1)]]];
        }
        _imageArr = arrM;
    }
    return _imageArr;
}


@end
